package model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import controller.ConnectDB;
import controllerBeans.UsuarioLogin;

public class UsuarioLoginDAO {

	private Connection connection;
	
	public UsuarioLoginDAO(){
		
	}
	
	public UsuarioLogin getUsuarioLogin(String email, String senha){
		
		UsuarioLogin ul = new UsuarioLogin();
		
		String sql = "SELECT * FROM usuario WHERE email=? AND senha=?";
		try {
			this.connection = new ConnectDB().getConnection();
			PreparedStatement stmt = connection.prepareStatement(sql);
			stmt.setString(1, email);
			stmt.setString(2, senha);
			ResultSet rs = stmt.executeQuery();
			
			if(!rs.next()){
				System.out.println("Não está cadastrado ainda");
				return null;
				
			}else{
				ul.setNome(rs.getString("nome"));
				ul.setEmail(rs.getString("email"));
				ul.setId(rs.getInt("id"));
				ul.setTipo(rs.getInt("tipo"));
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
		return ul;
	}
}
